#include "test_Buffer.h"
#include "app/app_buffer.h"
#include <assert.h>
#include <string.h>

void test_buffer()
{
    Buffer buffer;
    char buf[20];
    int read_len;
    app_buffer_init(&buffer, 16);

    app_buffer_write(&buffer, "abcd", 4);
    app_buffer_write(&buffer, "ghijkl", 6);

    assert(buffer.data_len == 10);

    read_len = app_buffer_read(&buffer, buf, 20);
    assert(read_len == 10);
    assert(memcmp("abcdghijkl", buf, 10) == 0);

    app_buffer_write(&buffer, "abcd", 4);
    app_buffer_write(&buffer, "ghijkl", 6);
    assert(buffer.data_len == 10);

    read_len = app_buffer_read(&buffer, buf, 20);
    assert(read_len == 10);
    assert(memcmp("abcdghijkl", buf, 10) == 0);

    app_buffer_free(&buffer);
}